import Vue from "vue";
import VueRouter from "vue-router";
import Home from '@/views/Home.vue'
import LeftNav from '@/components/leftNav.vue';

import DataSource from "../views/DataSource.vue";
import Project from "../views/Project/Project.vue";
import Module from "../views/Project/Module.vue";
import Comp from "../views/Project/Component.vue";
import Model from "../views/Project/Model.vue";
import Form from "../views/Project/Form.vue";
import Plug from "../views/Project/Plug.vue";
import menuMng from "../views/Project/MenuMng.vue";
import Enums from "../views/Project/Enums.vue";//枚举

import Project_product from "../views/Product/Project.vue";
import Module_product from "../views/Product/Module.vue";
import Comp_product from "../views/Product/Component.vue";
import Model_product from "../views/Product/Model.vue";
import Form_product from "../views/Product/Form.vue";
import Enums_product from "../views/Product/Enums.vue";
import Plug_product from "../views/Product/Plug.vue";
import MenuMng_product from "../views/Product/MenuMng.vue";

import User from "../views/User.vue";


// 懒加载方式，当路由被访问的时候才加载对应组件
const Login = resolve => require(['@/views/Login'], resolve)

Vue.use(VueRouter);

let routes = [
    {
      path: '/login',
      type: 'login',
      component: Login
    },
    // {
    //   path: '*',
    //   component: NotFound
    // },
    {
      path: '/',
      type: 'home', // 根据type区分不同模块（顶部导航）
      name: 'home', // 根据name区分不同子模块（左侧导航）
      redirect: '/dataSource',
      component: Home,
      menuShow: true,
      children: [
        {
          path: '/dataSource',
          component: LeftNav,
          name: 'dataSource', // 当前路由的name
          leaf: true, // 只有一个节点
          iconCls: 'el-icon-s-management', // 图标样式class
          menuShow: true,
          children: [
            { path: '/dataSource', component: DataSource, name: '数据源', menuShow: true }
          ]
        },
        {
          path: '/project',
          component: LeftNav,
          name: '项目',
          iconCls: 'el-icon-s-platform',
          menuShow: true,
          children: [
            { path: '/project/project', component: Project, name: '解决方案', menuShow: true },
            { path: '/project/module', component: Module, name: '模块', menuShow: true },
            { path: '/project/component', component: Comp, name: '组件', menuShow: true },
            { path: '/project/model', component: Model, name: '模型', menuShow: true },
            { path: '/project/modelAttributes', component: ()=>import("@/views/Project/Modelattributes"), name: '模型属性', menuShow: false },
            { path: '/project/Form', component: Form, name: '表单', menuShow: true },
            { path: '/project/Part', component: ()=>import("@/views/Project/Part"), name: '部件', menuShow: false },
            { path: '/project/PartField', component: ()=>import("@/views/Project/PartField"), name: '部件项', menuShow: false },
            { path: '/project/PartBtn', component: ()=>import("@/views/Project/PartBtn"), name: '部件按钮', menuShow: false },
            // { path: '/project/menuMng', component: menuMng, name: '菜单管理', menuShow: true },
            // { path: '/project/Enums', component: Enums, name: '枚举', menuShow: true },
            // { path: '/project/EnumsItems', component: ()=>import("@/views/Project/EnumsItems"), name: '枚举项', menuShow: false },
            // { path: '/project/plug', component: Plug, name: '插件', menuShow: true },
          ]
        },
        {
          path: '/product',
          component: LeftNav,
          name: '产品',
          iconCls: 'el-icon-s-finance',
          menuShow: true,
          children: [
            { path: '/product/project', component: Project_product, name: '解决方案', menuShow: true },
            { path: '/product/module', component: Module_product, name: '模块', menuShow: true },
            { path: '/product/componentd', component: Comp_product, name: '组件', menuShow: true },
            { path: '/product/model', component: Model_product, name: '模型', menuShow: true },
            { path: '/product/modelAttributes', component: ()=>import("@/views/Product/Modelattributes"), name: '模型属性', menuShow: false },
            { path: '/product/Form', component: Form_product, name: '表单', menuShow: true },
            { path: '/product/Part', component: ()=>import("@/views/Product/Part"), name: '部件', menuShow: false },
            { path: '/product/PartField', component: ()=>import("@/views/Product/PartField"), name: '部件项', menuShow: false },
            { path: '/product/PartBtn', component: ()=>import("@/views/Product/PartBtn"), name: '部件按钮', menuShow: false },
            // { path: '/product/menuMng', component: MenuMng_product, name: '菜单管理', menuShow: true },
            // { path: '/product/Enums', component: Enums_product, name: '枚举', menuShow: true },
            // { path: '/product/EnumsItems', component: ()=>import("@/views/Product/EnumsItems"), name: '枚举项', menuShow: false },
            // { path: '/product/plug', component: Plug_product, name: '插件', menuShow: true },
          ]
        },

        {
          path: '/menuMng',
          component: LeftNav,
          name: 'menuMng', // 当前路由的name
          leaf: true, // 只有一个节点
          iconCls: 'el-icon-s-finance', // 图标样式class
          menuShow: true,
          children: [
            { path: '/menuMng', component: menuMng, name: '菜单管理', menuShow: true },
          ]
        },

        {
          path: '/enums',
          component: LeftNav,
          name: 'enums', // 当前路由的name
          leaf: true, // 只有一个节点
          iconCls: 'el-icon-s-finance', // 图标样式class
          menuShow: true,
          children: [
            { path: '/enums', component: Enums, name: '枚举', menuShow: true },
            { path: '/enums/EnumsItems', component: ()=>import("@/views/Project/EnumsItems"), name: '枚举项', menuShow: false },
          ]
        },

        {
          path: '/plug',
          component: LeftNav,
          name: 'plug', // 当前路由的name
          leaf: true, // 只有一个节点
          iconCls: 'el-icon-s-finance', // 图标样式class
          menuShow: true,
          children: [
            { path: '/plug', component: Plug, name: '插件', menuShow: true },
            
          ]
        },



        {
          path: '/user',
          component: LeftNav,
          name: 'user', // 当前路由的name
          leaf: true, // 只有一个节点
          iconCls: 'el-icon-s-custom', // 图标样式class
          menuShow: true,
          children: [
            { path: '/user', component: User, name: '用户', menuShow: true }
          ]
        }

      ]
    },
  ]

const router = new VueRouter({
    routes
});

router.beforeEach((to, from, next) => {
  // console.log('to:' + to.path)
  if (to.path.startsWith('/login')) {
    localStorage.removeItem('access-user')
    next()
  }
  else {
    let user = JSON.parse(localStorage.getItem('access-user'))
    if (!user) {
      next({path: '/login'})
    }
    else {
      next()
    }
  }
});

export default router;
